<?
class JCAT_WidgetLookup
{
	private $arrWidgets = array() ;
	private $arrWidgetsClass = array() ;


	public function AddWidgetName($sName,$sClass='')
	{
		if( !isset($this->arrWidgets[$sName]) )
		{
			$this->arrWidgets[$sName] = null ;
			if($sClass)
				$this->arrWidgetsClass[$sName] = $sClass ;
		}
	}

	public function Lookup($aParentWidget)
	{
		if( !method_exists($aParentWidget,'get_children') )
			return ;

		// 菜单
		if( in_array(get_class($aParentWidget),array('GtkMenuItem','GtkImageMenuItem','GtkCheckMenuItem,','GtkTearoffMenuItem')) )
		{
			$aChild = $aParentWidget->get_submenu() ;
			if($aChild)
			{
				$this->PutInWidget($aChild) ;
				$this->Lookup($aChild) ;
			}
		}

		// 一般容器
		else
		{
			$arrChildren = $aParentWidget->get_children() ;
			foreach($arrChildren as $aChild)
			{
				$this->PutInWidget($aChild) ;
				$this->Lookup($aChild) ;
			}
		}
	}
	
	public function PutInWidget($aChild)
	{
		$sName = Glade::get_widget_name($aChild) ;
		if( array_key_exists($sName,$this->arrWidgets) )
		{
			if( isset($this->arrWidgetsClass[$sName]) )
			{
				if($this->arrWidgetsClass[$sName]==get_class($aChild))
					$this->arrWidgets[$sName] = $aChild ;
			}
			else 
				$this->arrWidgets[$sName] = $aChild ;
		}
	}

	public function GetWidget($sName)
	{
		return $this->arrWidgets[$sName] ;
	}
}
?>